local sk__taiping = fk.CreateSkill {

  name = "sk__taiping",

  tags = {  },

}



sk__taiping:addEffect(fk.EventPhaseStart, {
  name = "sk__taiping",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__taiping.name) and player.phase == Player.Start and
      table.find(player.room.alive_players, function (p)
        return p:getMark("@sk__taiping") > 0
      end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__taiping.name, nil, "#sk__taiping-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
    local n, sum = 0, 0
    for _, p in ipairs(room:getOtherPlayers(player)) do
      n = n + p:getMark("@sk__taiping")
      room:setPlayerMark(p, "@sk__taiping", 0)
      sum = sum + p:getHandcardNum()
    end
    n = n + player:getMark("@sk__taiping")
    room:setPlayerMark(player, "@sk__taiping", 0)
    player:drawCards(n, sk__taiping.name)
    if player:getHandcardNum() > sum and room:askForSkillInvoke(player, sk__taiping.name, nil, "#sk__taiping-damage") then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p.dead then
          room:damage({
            from = player,
            to = p,
            damage = 1,
            skillName = sk__taiping.name,
          })
        end
      end
    end
  end,
})

return sk__taiping